<script lang="ts" setup>
// @ts-ignore
import {getTalks} from "~/server/say.service";
// @ts-ignore
import {SayPath} from "~/config/SystemConfig";

definePageMeta({
    layout: false,
})
useHead({
    bodyAttrs: {
        class: 'archive category category-say category-1'
    }
})
const talkTitle = ref('壹句话')
const talkDesc = ref('关于明天的事，我们后天就知道了。')
const pagination = reactive({
    size: 12,
    total: 0,
    current: 1
})
const saysList = ref('' as any)
const count = ref(0)

function getSaysList() {
    const params = {
        current: pagination.current,
        size: pagination.size
    }
    getTalks(params).then(({data}: any) => {
        saysList.value = data.data.records
        count.value = data.data.count
    })
}

function nextPage() {
    if (pagination.current * pagination.size > count.value){
        ElMessage.warning('暂无更多说说')
        return
    }
    pagination.current = pagination.current + 1
    getSaysList()
}

onMounted(() => {
    getSaysList()
})
</script>
<template>
    <NuxtLayout name="grid">
        <template v-slot:nav>
            <Nav :title="'壹句话'"/>
        </template>
        <template v-slot:main>
            <PageHeader :title="talkTitle" :desc="talkDesc"/>
            <div class="post_box  say">
                <template v-for="item in saysList">
                    <article class="entry-preview post status-publish hentry category-say fade-before fade-after">
                        <div class="thumbnail_box">
                            <a class="thumbnail" :href="SayPath.Path+item.id" rel="bookmark">
                                <img :src="item.imgs[0]"
                                     :href="item.imgs[0]"
                                     class="attachment-post-thumbnail size-post-thumbnail loaded" alt=""
                                     loading="lazy" data-fancybox="gallery">
                            </a>
                        </div>
                        <div class="entry-thyuupost">
                            <header class="entry-header">
                                <time class="post-time" :datetime="item.createTime">
                                    {{ timeAgo(new Date(item.createTime)) }}
                                </time>
                                <h6 class="entry-title">
                                    <a :href="SayPath.Path+item.id" rel="bookmark">
                                        {{ item.content }}
                                    </a>
                                </h6>
                            </header>
                            <footer class="post-meta">
                                <div class="post-mark">
                                    <span class="tag">
                                        <a href="#main" rel="category tag">
                                            壹句话
                                        </a>
                                    </span>
                                </div>
                            </footer>
                        </div>
                    </article>
                </template>
            </div>
            <nav class="navigation page-navigation" role="navigation">
                <div class="nav-next">
                    <a href="#main" @click="nextPage">
                        <span class="meta-nav">下一页</span>
                    </a>
                </div>
            </nav>
        </template>
    </NuxtLayout>
</template>
<style scoped>

</style>
